package cz.myslivec.slovicka.xml.converter;

import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;

import cz.myslivec.slovicka.entity.Lesson;
import cz.myslivec.slovicka.util.converter.AConverterBase;
import cz.myslivec.slovicka.xml.model.LessonDTO;

@Name("lessonConverter")
@AutoCreate
public class LessonConverter extends AConverterBase<Lesson, LessonDTO> {

	@In
	VocableTypeConverter vocableTypeConverter;
	
	@In
	VocableConverter vocableConverter;
	
	public LessonConverter() {
		super();
	}

	@Override
	protected LessonDTO getTo(LessonDTO result, Lesson from) {
		result.setId(from.getId());
		result.setName(from.getName());
		result.setNote(from.getNote());
		result.setVocType(vocableTypeConverter.convert(from.getVocType()));
		result.setVocables(vocableConverter.convertList(from.getVocables()));
		return result;
	}

	@Override
	protected Lesson getFrom(Lesson result, LessonDTO to) {
		result.setId(to.getId());
		result.setName(to.getName());
		result.setNote(to.getNote());
		result.setVocType(vocableTypeConverter.convertBack(to.getVocType()));
		result.setVocables(vocableConverter.convertBackList(to.getVocables()));
		return result;
	}

	@Override
	protected LessonDTO getToInstance() {
		return new LessonDTO();
	}

	@Override
	protected Lesson getFromInstance() {
		return new Lesson();
	}

}
